use crate::system::render::{RenderSystem, render_pass::mesh_render_pass::{MeshPassDescriptorSetLayoutType, MeshPassPipelineType}};

use super::SceneSystem;

pub mod static_mesh;


pub trait ObjectTrait {
    // fn set_location(&mut self, in_location :cgmath::Vector3<f32>);
    fn get_model_mat(&self) -> cgmath::Matrix4<f32>;
    fn tick(&mut self, delta_time: f32);
    fn get_id(&self) -> usize;
}
pub struct ObjectBase {
    pub id                      : usize,

    pub location                : cgmath::Vector3<f32>,
    pub rotation                : cgmath::Vector3<f32>,
    pub scale                   : cgmath::Vector3<f32>,
}

impl ObjectTrait for ObjectBase {
    fn get_model_mat(&self) -> cgmath::Matrix4<f32> {
        let model_mat = 
            cgmath::Matrix4::from_translation(self.location) * 
            cgmath::Matrix4::from_nonuniform_scale(
                self.scale[0],
                self.scale[1],
                self.scale[2]
            ) * 
            cgmath::Matrix4::from_angle_x(cgmath::Deg(self.rotation[0])) *
            cgmath::Matrix4::from_angle_y(cgmath::Deg(self.rotation[1])) *
            cgmath::Matrix4::from_angle_z(cgmath::Deg(self.rotation[2]));

        model_mat
    }

    fn tick(&mut self, delta_time: f32) {
    }

    fn get_id(&self) -> usize {
        self.id
    }
}

impl ObjectBase {
    pub fn new(id: usize, render_system: &mut RenderSystem) -> Self {
        let object = Self {
            id                      : id,
            location                : cgmath::Vector3::new(id as f32 * 2.0, 0.0, id as f32 * 2.0),
            rotation                : cgmath::Vector3::new(0.0, 0.0, 0.0),
            scale                   : cgmath::Vector3::new(1.0, 1.0, 1.0),
        };
        render_system.render_scene.add_render_entity(
            id,
            &render_system.vk_context, 
            &vec![render_system.mesh_render_pass.pipelines[MeshPassPipelineType::MeshPipeline as usize].descriptor_set_layouts[MeshPassDescriptorSetLayoutType::PerMesh as usize]]);

        object
    }
}